# U-boot with patches to make the PinePhone boot faster and have control over the ddr clock speed
pkgname=u-boot-pinephone
pkgver=2021.01_git20201228
pkgrel=0
# Last commit from "crust" branch, as used in "crust-meta":
# https://gitlab.com/pine64-org/crust-meta/-/blob/8886bcc829179bf77216fade71f0ede9bd014e67/Makefile#L78
_commit="7492749fec31b1086bc8933bf113a766aea021aa"
pkgdesc="u-boot bootloader for the PINE64 PinePhone"
url="https://gitlab.com/pine64-org/u-boot"
arch="aarch64"
license="GPL-2.0-or-later OFL-1.1 BSD-2-Clause BSD-3-Clause eCos-2.0 IBM-pibs
	ISC LGPL-2.0-only LGPL-2.1-only X11"
makedepends="$depends_dev bc dtc python3-dev py3-setuptools swig bison flex openssl-dev arm-trusted-firmware-sun50i crust"
options="!check"
source="https://gitlab.com/pine64-org/u-boot/-/archive/$_commit/u-boot-$_commit.tar.gz
	update-u-boot
	"
builddir="$srcdir/u-boot-$_commit"

build() {
	touch include/config.h
	LC_ALL=C date +'#define U_BOOT_DATE "%b %d %C%y"' > include/timestamp_autogenerated.h
	LC_ALL=C date +'#define U_BOOT_TIME "%T"' >> include/timestamp_autogenerated.h

	export BL31="/usr/share/arm-trusted-firmware-sun50i/bl31.bin"
	export SCP="/usr/share/crust/pinephone/scp.bin"
	export BUILD_DIR="$builddir"/build
	mkdir -p "$BUILD_DIR"
	make O="$BUILD_DIR" HOSTCC=gcc ARCH=arm pinephone_defconfig
	make O="$BUILD_DIR" HOSTCC=gcc ARCH=arm all
}

prepare() {
	default_prepare

	if ! grep -q "CONFIG_DRAM_CLK=552" configs/pinephone_defconfig; then
		error "CONFIG_DRAM_CLK must be 552!"
		return 1
	fi
}

package() {
	cd build
	install -D -m644 "u-boot-sunxi-with-spl.bin" \
		"$pkgdir"/usr/share/u-boot/pine64-pinephone/u-boot-sunxi-with-spl.bin
	install -D -m 755 "$srcdir"/update-u-boot "$pkgdir"/usr/sbin/update-u-boot
}

sha512sums="73b132cdc26113a83d060f0d243320ca989b4efa98fe95a2205526a42f615ced7046bb9d4878c67a9a550b04c2519d90be3c2272be97c878d759bf5d027cf536  u-boot-7492749fec31b1086bc8933bf113a766aea021aa.tar.gz
4a3a1772a7309d44e7977dee4aca499d5c79675d99cda1395d8765abb415b8456260c7a989650f0bd2dfda0377af2346917fbcbf3e356a36265ed07e161ddc3b  update-u-boot"
